/**
 * 功能描述
 */

define(function (require, exports, module) {
	var Grid = require("grid");
	var aw = require("ajaxwrapper");
    var instance = {
        initComponent: function (params,widget) {
        	var fgrid = new Grid({
        		parentNode: ".J-fgrid",
        		autoRender : false,
        		model:{
        			url:"api/checkinimplement/query",
        			params:function(){
        				var subnav = widget.get("subnav");
        				return{
        					"nonMemberGroup.status":"Reserve",
        					fetchProperties:"pkCIImplement,version,roomStatus.*,status.*," +
							"dataSource.*,signUpNum," + 
							"nonMemGroupReserve.*,nonMemGroupReserve.nonMemberGroup," + 
							"nonMemGroupReserve.nonMemberGroup.servicePoint.name," + 
							"nonMemGroupReserve.nonMemberGroup.*," + 
							"nonMemGroupReserve.signUpRooms.*," + 
							"nonMemGroupReserve.signUpRooms.roomType.*," + 
							"nonMemGroupReserve.nonMemberGroup.signUps.version," + 
							"nonMemGroupReserve.nonMemberGroup.operator.servicePoint.name," + 
							"groupReserve.planItemGroup.allianceOrg.name," +
							"groupReserve.signUpNumber," +
							"groupReserve.checkInDate," +
							"groupReserve.checkOutDate," +
							"groupReserve.planItemGroup.planItem.destination.name," +
							"groupReserve.planItemGroup.signUps.version," +
							"groupReserve.planItemGroup.signUps.pkSignUpRegister," +
							"groupReserve.roomRegisters.pkRoomRegister," +
							"groupReserve.roomRegisters.room.code," +
							"groupReserve.roomRegisters.room.orgBuilding.name," +
							"groupReserve.planItemGroup.servicePoint.pkServicePoint," +
							"groupReserve.planItemGroup.servicePoint.name," +
							"descript" 
        				}
        			},
        			columns:[{
        				
            			id : "betch",
    					type : "button",
    					text:"批量设置",						
    					handler:function(){
    						widget._betch(widget,true,null);
    					}
    					
        			},{
        				name:"groupReserve",
        				label:"组团单位/预约人",
        				format: function(value,row){
        					if(row.dataSource.key == "GroupReserve"){
        						if(value.planItemGroup.allianceOrg){
        							return value.planItemGroup.allianceOrg.name;
        						}else{
        							return value.planItemGroup.servicePoint.name
        						}
        					}else{
    							return row.nonMemGroupReserve.nonMemberGroup.contactName;
        					}
        				}
        			},{
        				name:"destinationName",
        				label:"目的地",
        				format : function(value, row){
        					if(row.dataSource.key == "GroupReserve"){
        						return row.groupReserve.planItemGroup.planItem.destination.name;
        					}else{
        						return row.nonMemGroupReserve.nonMemberGroup.servicePoint == null ? "" : row.nonMemGroupReserve.nonMemberGroup.servicePoint.name;
        					}
        				}
        			},{
        				name:"groupReserve.checkInDate",
        				label:"开始日期",
        				format:"date",
        				format:function(value,row){
        					if(row.dataSource.key == "GroupReserve"){
        						return moment(value).format("YYYY-MM-DD");
        					}else{
        						return moment(row.nonMemGroupReserve.nonMemberGroup.checkInDate).format("YYYY-MM-DD");
        					}
        				}
        			},{
        				name:"groupReserve.checkOutDate",
        				label:"结束日期",
        				format:"date",
        				format:function(value,row){
        					if(row.dataSource.key == "GroupReserve"){
        						return moment(value).format("YYYY-MM-DD");
        					}else{
        						return moment(row.nonMemGroupReserve.nonMemberGroup.checkOutDate).format("YYYY-MM-DD");
        					}
        				}
        			},{
        				name:"",
        				label:"报名人数",
        				format:function(value,row){
        					if(row.dataSource.key == "GroupReserve"){
        						return row.signUpNum;
        					}else{
        						return row.nonMemGroupReserve.nonMemberGroup.perNumber;
        					}
        				}
        			}]
        		},
        		
        	});
        	$(".J-fgrid .J-grid-footer").append('<div> <button style:"center">确定</button><\div>');
        	widget.set("fgrid",fgrid)
        }
    };
    module.exports = instance;
});
